package com.gemme.gemme.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.gemme.gemme.R;
import com.gemme.gemme.home.ShopProductInfoBean;
import com.gemme.gemme.wode.ProductNewActivity;

import java.util.List;

//首页水平滚动
public class HomeHorSrollView extends RelativeLayout {
    private Context context;
    public HomeHorSrollView(Context context) {
        this(context,null);
    }

    public HomeHorSrollView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public HomeHorSrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    LinearLayout ll_content;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.home_hor_srollview,this);
        ll_content = findViewById(R.id.ll_content);

       /* ll_content.addView(new SpecialPriceView(context));
        ll_content.addView(new SpecialPriceView(context));
        ll_content.addView(new SpecialPriceView(context));
        ll_content.addView(new SpecialPriceView(context));
        ll_content.addView(new SpecialPriceView(context));*/
    }

    public void setDataList(List dataLsit) {
        try {
            List<ShopProductInfoBean.DataBean.NewObjBean> list = dataLsit;
            for (int i = 0; i < list.size(); i++) {
                ShopProductInfoBean.DataBean.NewObjBean newObjBean = list.get(i);
                SpecialPriceView specialPriceView = new SpecialPriceView(context);
                specialPriceView.setIv(newObjBean.getAbbreviationPic())
                .settv_name(newObjBean.getProductName())
                .settv_desc(newObjBean.getProductDesc())
                .settv_price(newObjBean.getProductPrice() + "")
//                .settv_dis_price(newObjBean.getProductPrice() + "")
                .settv_dis_price(newObjBean.getPrice() + "")
                ;
                ll_content.addView(specialPriceView);

                specialPriceView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, ProductNewActivity.class);
                        intent.putExtra("id",newObjBean.getProductId());
                        intent.putExtra("brandId",newObjBean.getBrandId() + 0L);
                        context.startActivity(intent);
                    }
                });
            }

        }catch (Exception e){

        }
    }
}
